QT5.9移植ARM实现界面UI旋转90°

您所在的位置:网站首页 qt arm平台 QT5.9移植ARM实现界面UI旋转90°

QT5.9移植ARM实现界面UI旋转90°

#QT5.9移植ARM实现界面UI旋转90°| 来源: 网络整理| 查看: 265

在QT4中,对于界面旋转有QWS_DISPLAY,但新版QT5中,已经废弃这种翻转方式,只能通过QGraphicsView和QGraphicsProxyWidget旋转(详情查看:https://blog.csdn.net/cao269631539/article/details/76153927),但在旋转后界面会多出滑动条或界面不对齐,最主要缺点在于界面UI翻转后触摸未得到翻转。在arm移植中往往不容易接受。

#include #include #include #include "./form.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); Form *form = new Form; //项目主窗口 QGraphicsScene *scene = new QGraphicsScene; QGraphicsProxyWidget *w = scene->addWidget(form); w->setRotation(90); QGraphicsView *view = new QGraphicsView(scene); view->resize(810, 610); view->show(); return a.exec(); }

在经过几次摸索后,发现qt官方其实给出了QT旋转的补丁,以下是Qt5.4补丁,该补丁缺陷在触摸对不齐补丁下载地址:https://naza.shucy.workers.dev/-----https://borkedlabs.com/misc/qt5.4_linuxfb_rotation.patch_.zip该补丁需要翻墙;

https://download.csdn.net/download/qq_15725099/11912591

diff --git a/src.orig/plugins/platforms/linuxfb/qlinuxfbscreen.cpp b/src/plugins/platforms/linuxfb/qlinuxfbscreen.cpp index a66c9fa..a5b5f13 100644 --- a/src.orig/plugins/platforms/linuxfb/qlinuxfbscreen.cpp +++ b/src/plugins/platforms/linuxfb/qlinuxfbscreen.cpp @@ -290,7 +290,7 @@ static void blankScreen(int fd, bool on) } QLinuxFbScreen::QLinuxFbScreen(const QStringList &args) - : mArgs(args), mFbFd(-1), mBlitter(0) + : mArgs(args), mFbFd(-1), mBlitter(0), mRotation(90) { } @@ -316,6 +316,7 @@ bool QLinuxFbScreen::initialize() QRegularExpression mmSizeRx(QLatin1String("mmsize=(\\d+)x(\\d+)")); QRegularExpression sizeRx(QLatin1String("size=(\\d+)x(\\d+)")); QRegularExpression offsetRx(QLatin1String("offset=(\\d+)x(\\d+)")); + QRegularExpression rotationRx(QLatin1String("rotation=(0|90|180|270)")); QString fbDevice, ttyDevice; QSize userMmSize; @@ -337,6 +338,8 @@ bool QLinuxFbScreen::initialize() ttyDevice = match.captured(1); else if (arg.contains(fbRx, &match)) fbDevice = match.captured(1); + else if (arg.contains(rotationRx, &match)) + mRotation = match.captured(1).toInt(); } if (fbDevice.isEmpty()) { @@ -375,9 +378,17 @@ bool QLinuxFbScreen::initialize() mDepth = determineDepth(vinfo); mBytesPerLine = finfo.line_length; QRect geometry = determineGeometry(vinfo, userGeometry); + QRect originalGeometry = geometry; + if( mRotation == 90 || mRotation == 270 ) + { + int tmp = geometry.width(); + geometry.setWidth(geometry.height()); + geometry.setHeight(tmp); + } + mGeometry = QRect(QPoint(0, 0), geometry.size()); mFormat = determineFormat(vinfo, mDepth); - mPhysicalSize = determinePhysicalSize(vinfo, userMmSize, geometry.size()); + mPhysicalSize = determinePhysicalSize(vinfo, userMmSize, originalGeometry.size()); // mmap the framebuffer mMmap.size = finfo.smem_len; @@ -387,11 +398,11 @@ bool QLinuxFbScreen::initialize() return false; } - mMmap.offset = geometry.y() * mBytesPerLine + geometry.x() * mDepth / 8; + mMmap.offset = originalGeometry.y() * mBytesPerLine + originalGeometry.x() * mDepth / 8; mMmap.data = data + mMmap.offset; QFbScreen::initializeCompositor(); - mFbScreenImage = QImage(mMmap.data, geometry.width(), geometry.height(), mBytesPerLine, mFormat); + mFbScreenImage = QImage(mMmap.data, originalGeometry.width(), originalGeometry.height(), mBytesPerLine, mFormat); QByteArray hideCursorVal = qgetenv("QT_QPA_FB_HIDECURSOR"); #if !defined(Q_OS_ANDROID) || defined(Q_OS_ANDROID_NO_SDK) @@ -436,7 +447,26 @@ QRegion QLinuxFbScreen::doRedraw() QVector rects = touched.rects(); for (int i = 0; i < rects.size(); i++) + { + if( mRotation == 90 || mRotation == 270 ) + { + mBlitter->translate(mGeometry.height()/2, mGeometry.width()/2); + } + else if( mRotation == 180 ) + { + mBlitter->translate(mGeometry.width()/2, mGeometry.height()/2); + } + + if( mRotation != 0 ) + { + mBlitter->rotate(mRotation); + mBlitter->translate(-mGeometry.width()/2, -mGeometry.height()/2); + } + mBlitter->drawImage(rects[i], *mScreenImage, rects[i]); + + mBlitter->resetTransform(); + } return touched; } diff --git a/src.orig/plugins/platforms/linuxfb/qlinuxfbscreen.h b/src/plugins/platforms/linuxfb/qlinuxfbscreen.h index 1997d46..a34414f 100644 --- a/src.orig/plugins/platforms/linuxfb/qlinuxfbscreen.h +++ b/src/plugins/platforms/linuxfb/qlinuxfbscreen.h @@ -57,6 +57,7 @@ private: QStringList mArgs; int mFbFd; int mTtyFd; + int mRotation; QImage mFbScreenImage; int mBytesPerLine;

以下是我在Qt5.9和5.11中移植Arm修改源码,亲测可用,且移植成功。

/**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the plugins of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see https://www.qt.io/terms-conditions. For further ** information use the contact form at https://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 3 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPL3 included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 3 requirements ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 2.0 or (at your option) the GNU General ** Public license version 3 or any later version approved by the KDE Free ** Qt Foundation. The licenses are as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 ** included in the packaging of this file. Please review the following ** information to ensure the GNU General Public License requirements will ** be met: https://www.gnu.org/licenses/gpl-2.0.html and ** https://www.gnu.org/licenses/gpl-3.0.html. ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #ifndef QLINUXFBSCREEN_H #define QLINUXFBSCREEN_H #include QT_BEGIN_NAMESPACE class QPainter; class QFbCursor; class QLinuxFbScreen : public QFbScreen { Q_OBJECT public: QLinuxFbScreen(const QStringList &args); ~QLinuxFbScreen(); bool initialize() override; QPixmap grabWindow(WId wid, int x, int y, int width, int height) const override; QRegion doRedraw() override; private: QStringList mArgs; int mFbFd; int mTtyFd; // add by immortal start int mRotation; // add by immortal end QImage mFbScreenImage; int mBytesPerLine; int mOldTtyMode; struct { uchar *data; int offset, size; } mMmap; QPainter *mBlitter; }; QT_END_NAMESPACE #endif // QLINUXFBSCREEN_H /**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the plugins of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see https://www.qt.io/terms-conditions. For further ** information use the contact form at https://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 3 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPL3 included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 3 requirements ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 2.0 or (at your option) the GNU General ** Public license version 3 or any later version approved by the KDE Free ** Qt Foundation. The licenses are as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 ** included in the packaging of this file. Please review the following ** information to ensure the GNU General Public License requirements will ** be met: https://www.gnu.org/licenses/gpl-2.0.html and ** https://www.gnu.org/licenses/gpl-3.0.html. ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #include "qlinuxfbscreen.h" #include #include #include #include #include #include // overrides QT_OPEN #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include QT_BEGIN_NAMESPACE static int openFramebufferDevice(const QString &dev) { int fd = -1; if (access(dev.toLatin1().constData(), R_OK|W_OK) == 0) fd = QT_OPEN(dev.toLatin1().constData(), O_RDWR); if (fd == -1) { if (access(dev.toLatin1().constData(), R_OK) == 0) fd = QT_OPEN(dev.toLatin1().constData(), O_RDONLY); } return fd; } static int determineDepth(const fb_var_screeninfo &vinfo) { int depth = vinfo.bits_per_pixel; if (depth== 24) { depth = vinfo.red.length + vinfo.green.length + vinfo.blue.length; if (depth vinfo.yres) h = vinfo.yres; int xxoff = userGeometry.x(), yyoff = userGeometry.y(); if (xxoff != 0 || yyoff != 0) { if (xxoff < 0 || xxoff + w > (int)(vinfo.xres)) xxoff = vinfo.xres - w; if (yyoff < 0 || yyoff + h > (int)(vinfo.yres)) yyoff = vinfo.yres - h; xoff += xxoff; yoff += yyoff; } else { xoff += (vinfo.xres - w)/2; yoff += (vinfo.yres - h)/2; } } else { w = vinfo.xres; h = vinfo.yres; } if (w == 0 || h == 0) { qWarning("Unable to find screen geometry, using 320x240"); w = 320; h = 240; } return QRect(xoff, yoff, w, h); } static QSizeF determinePhysicalSize(const fb_var_screeninfo &vinfo, const QSize &mmSize, const QSize &res) { int mmWidth = mmSize.width(), mmHeight = mmSize.height(); if (mmWidth {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0}}; const fb_bitfield bgr888[4] = {{0, 8, 0}, {8, 8, 0}, {16, 8, 0}, {0, 0, 0}}; if (memcmp(rgba, rgb888, 3 * sizeof(fb_bitfield)) == 0) { format = QImage::Format_RGB888; } else if (memcmp(rgba, bgr888, 3 * sizeof(fb_bitfield)) == 0) { format = QImage::Format_RGB888; // pixeltype = BGRPixel; } break; } case 18: { const fb_bitfield rgb666[4] = {{12, 6, 0}, {6, 6, 0}, {0, 6, 0}, {0, 0, 0}}; if (memcmp(rgba, rgb666, 3 * sizeof(fb_bitfield)) == 0) format = QImage::Format_RGB666; break; } case 16: { const fb_bitfield rgb565[4] = {{11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0}}; const fb_bitfield bgr565[4] = {{0, 5, 0}, {5, 6, 0}, {11, 5, 0}, {0, 0, 0}}; if (memcmp(rgba, rgb565, 3 * sizeof(fb_bitfield)) == 0) { format = QImage::Format_RGB16; } else if (memcmp(rgba, bgr565, 3 * sizeof(fb_bitfield)) == 0) { format = QImage::Format_RGB16; // pixeltype = BGRPixel; } break; } case 15: { const fb_bitfield rgb1555[4] = {{10, 5, 0}, {5, 5, 0}, {0, 5, 0}, {15, 1, 0}}; const fb_bitfield bgr1555[4] = {{0, 5, 0}, {5, 5, 0}, {10, 5, 0}, {15, 1, 0}}; if (memcmp(rgba, rgb1555, 3 * sizeof(fb_bitfield)) == 0) { format = QImage::Format_RGB555; } else if (memcmp(rgba, bgr1555, 3 * sizeof(fb_bitfield)) == 0) { format = QImage::Format_RGB555; // pixeltype = BGRPixel; } break; } case 12: { const fb_bitfield rgb444[4] = {{8, 4, 0}, {4, 4, 0}, {0, 4, 0}, {0, 0, 0}}; if (memcmp(rgba, rgb444, 3 * sizeof(fb_bitfield)) == 0) format = QImage::Format_RGB444; break; } case 8: break; case 1: format = QImage::Format_Mono; //###: LSB??? break; default: break; } qDebug() translate(mGeometry.width()/2, mGeometry.height()/2); } if( mRotation != 0 ) { mBlitter->rotate(mRotation); mBlitter->translate(-mGeometry.width()/2, -mGeometry.height()/2); } mBlitter->drawImage(rects[i], mScreenImage, rects[i]); mBlitter->resetTransform(); } return touched; } // grabWindow() grabs "from the screen" not from the backingstores. // In linuxfb's case it will also include the mouse cursor. QPixmap QLinuxFbScreen::grabWindow(WId wid, int x, int y, int width, int height) const { if (!wid) { if (width < 0) width = mFbScreenImage.width() - x; if (height < 0) height = mFbScreenImage.height() - y; return QPixmap::fromImage(mFbScreenImage).copy(x, y, width, height); } QFbWindow *window = windowForId(wid); if (window) { const QRect geom = window->geometry(); if (width < 0) width = geom.width() - x; if (height < 0) height = geom.height() - y; QRect rect(geom.topLeft() + QPoint(x, y), QSize(width, height)); rect &= window->geometry(); return QPixmap::fromImage(mFbScreenImage).copy(rect); } return QPixmap(); } QT_END_NAMESPACE

当源码修改后放入qt源码目录,交叉编译移植即可,在arm运行qt程序向环境变量中加入:

博客文章迁移至:https://www.10sxj.com/

如有疑问加群:676977101(新群)



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3